// 简单版本的order控制器，用于测试orderModel重复声明问题
const goodsModel = require('../models/goods');
const orderModel = require('../models/order');
const { pool } = require('../config/db');
const upload = require('../config/upload');

// 创建订单
exports.createOrder = async (req, res) => {
  try {
    res.json({ success: true, message: '测试成功' });
  } catch (error) {
    res.status(500).json({ success: false, message: '测试失败' });
  }
};

// 获取用户订单列表
exports.getUserOrders = async (req, res) => {
  try {
    const userId = req.user?.id || null;
    const status = req.query.status || null;
    
    if (!userId) {
      return res.status(401).json({ success: false, message: '用户未登录' });
    }
    
    // 安全处理status参数
    const safeStatus = status || null;
    const orders = await orderModel.getUserOrders(userId, safeStatus);
    
    res.json({
      success: true,
      data: orders
    });
  } catch (error) {
    res.status(500).json({ success: false, message: '获取订单列表失败' });
  }
};

// 更新订单状态
exports.updateOrderStatus = async (req, res) => {
  try {
    res.json({ success: true, message: '测试成功' });
  } catch (error) {
    res.status(500).json({ success: false, message: '测试失败' });
  }
};

// 获取订单详情
exports.getOrderDetail = async (req, res) => {
  try {
    res.json({ success: true, message: '测试成功' });
  } catch (error) {
    res.status(500).json({ success: false, message: '测试失败' });
  }
};

// 上传订单
exports.uploadOrder = async (req, res) => {
  try {
    res.json({ success: true, message: '测试成功' });
  } catch (error) {
    res.status(500).json({ success: false, message: '测试失败' });
  }
};